#include "Random.h"
#include <time.h>
#include <cstdlib>
#include <math.h>

Random::Random()
{
    srand(time(NULL));
	low = -1.0;
	high = 1.0;
}

Random::Random(int seed) 
{
    srand(seed);
}

double Random::getUnifRand() 
{
	return low + (high-low) * std::rand() / RAND_MAX;
}

<<<<<<< local
double Random::getNormRand()
{
    double x, y, r;
=======
double NormRand :: rand()
{   double x;
	double x = (double)(std::rand());
	x = x % 2 - 1;  // make x locate in the integer [-1, 1)
	    
    double y;
	double y = (double)(std::rand());
	y = y % 2 - 1;
	
	double r;
	r = x*x + y*y;
	
	double z;
	
	if (r < 1) {
	    z = x*sqrt(-2*log(r)/r);
		} else {
		continue; }
		
	return z;
}
>>>>>>> other

    do {
       x = getUnifRand();
       y = getUnifRand();
       r = sqrt(x*x + y*y);
    } while (r >= 1.0);
    
    return x * sqrt(-2 * log(r) / r);
}
